/**
 * 扩展 Egg.js 应用实例 Application
 * */
const RPCClient = require("@alicloud/pop-core").RPCClient;

function initVodClient(accessKeyId, accessKeySecret) {
  const regionId = "cn-shanghai"; // 点播服务所在区域
  const client = new RPCClient({
    accessKeyId,
    accessKeySecret,
    endpoint: "https://vod." + regionId + ".aliyuncs.com",
    apiVersion: "2017-03-21",
  });
  return client;
}

let vodClient = null;

module.exports = {
  get vodClient() {
    const {
      config: {
        vod: { accessKeyId, accessKeySecret },
      },
    } = this;

    if (!vodClient) {
      vodClient = initVodClient(accessKeyId, accessKeySecret);
    }

    return vodClient;
  },
};
